
#include "format.h"

#include <stdio.h>

int rgb32_to_rgb24(void *src, uint32_t n_src, void *dest, uint32_t n_dest, uint32_t width, uint32_t height)
{
	uint32_t i = 0, j = 0;

	rgb24_class *rgb24 = NULL;
	rgb32_class *rgb32 = NULL;

	if(NULL != src && NULL != dest && 0 < width && 0 < height)
	{
		if((width * 4) * height != n_src || (width * 3) * height != n_dest)
		{
			return -1;
		}

		rgb24 = (rgb24_class *)dest;
		rgb32 = (rgb32_class *)src;

		for(j = 0; height > j; j++)
		{
			for(i = 0; width > i; i++)
			{
				*(rgb24 + width * 3 * j + i * 3 + 0) = *(rgb32 + width * 4 * j + i * 4 + 0);
				*(rgb24 + width * 3 * j + i * 3 + 1) = *(rgb32 + width * 4 * j + i * 4 + 1);
				*(rgb24 + width * 3 * j + i * 3 + 2) = *(rgb32 + width * 4 * j + i * 4 + 2);
			}
		}
		return 0;
	}
	return -1;
}